package com.v5ba;

import cn.hutool.core.io.file.FileWriter;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

public class Webmagic01 implements PageProcessor {
    private Site site = Site.me().setRetryTimes(3).setSleepTime(1000);
    public static StringBuilder sbStr = new StringBuilder();
    public void process(Page page) {
        String str = page.getHtml().xpath("//div[@class='dd-help-title']/text()").toString();
        if (str.indexOf("—") != -1) {
            sbStr.append(str).append("\r\n");
        }
    }

    public Site getSite() {
        return site;
    }
    public static void main(String[] args) {
        System.out.println("任务开始");
        Spider spider = Spider.create(new Webmagic01());
        String targetPath = "/Users/zhangyanhui/Desktop/db/a.txt";
        int startIndex = 1060281000;
        int endIndex = startIndex + 1;
        for (int i = startIndex; i < endIndex; i++){
            spider.addUrl("https://www.dingtalk.com/qidian/help-detail-"+i+".html");
        }
        spider.thread(5).run();
        System.out.println("任务结束");
        new FileWriter(targetPath).write(sbStr.toString());
    }
}
